<template>
  <view class="billing">
    <hx-navbar
      ref="hxnb"
      :config="config"
      @clickBtn="clickBtn"
      @onBack="onBack"
    ></hx-navbar>
    <view class="set-view" v-if="isSetShow">
      <u-icon
        class="up-icon"
        name="arrow-up-fill"
        color="#fff"
        size="28"
      ></u-icon>
      <view class="ul-view">
        <view class="li-view flex m-b-20" @click="onDelColor">
          <u-icon name="trash"></u-icon>
          <text class="m-l-20">删除该颜色</text>
        </view>
        <view class="li-view flex flex-aic" @click="onLikeSet">
          <clIcon type="icon-fuwuzhongxin" size="17"></clIcon>
          <text class="m-l-20">偏好设置</text>
        </view>
      </view>
    </view>
    <view class="top-box"></view>

    <view class="view" style="margin-top: -72rpx">
      <view class="info-card">
        <view class="view">
          <u-avatar shape="square" size="60"></u-avatar>
          <view class="info">
            <view>
              <text class="title"
                >{{ summaryDatas.code }} {{ summaryDatas.name }}</text
              >
            </view>
            <view v-if="summaryDatas.colorNumber">
              <text class="colorNumber" @click="toNextColor(1)">
                {{ summaryDatas.colorNumber }}
              </text>
            </view>
            <view v-else>
              <text class="blue" @click="toNextColor(1)"> 请选择颜色 </text>
            </view>
            <view class="warehouse-view m-t-10" @click="goPageWarehouse">
              <text class="warehouse"> {{ summaryDatas.storeName }}</text>
              <u-icon name="arrow-down" color="#353535" size="13"></u-icon>
            </view>
          </view>
        </view>
        <view
          class="change-color"
          @click="toNextColor(1)"
          v-if="summaryDatas.colorNumber"
        >
          <text>换颜色</text>
          <view class="p-t-10" v-if="showCon()">
            <text class="grey p-r-10">可发货</text>
            <text>暂无可发</text>
          </view>
        </view>
      </view>

      <view class="info-card">
        <view class="data-info">
          <view class="data-info-view"
            ><text
              :class="
                summaryDatas.snVoList.length <= 0 || summaryDatas.snVoList == ''
                  ? 'number'
                  : ''
              "
              ><input
                type="number"
                @focus="focus"
                v-model="summaryDatas.piecesCount"
                :disabled="summaryDatas.snVoList.length <= 0 ? false : true"
                class="input-box" /></text
          ></view>
          <view class="data-info-view"><text class="label">匹数</text></view>
        </view>
        <view class="data-info">
          <view class="data-info-view"
            ><text :class="summaryDatas.snVoList.length <= 0 ? 'number' : ''">
              <input
                @focus="focus"
                @input="inputPiecesChange"
                type="number"
                :disabled="summaryDatas.snVoList.length <= 0 ? false : true"
                v-model="summaryDatas.quantity"
                class="input-box"
              /> </text
          ></view>
          <view
            @click="
              toRoute(
                '/pages/application/pages/information/product-category/components/pricing-unit'
              )
            "
            class="data-info-view"
            ><text class="label"
              >{{ pageSource == "xsd" ? "出" : "入" }}库/{{
                summaryDatas.unitName
              }}</text
            ></view
          >
        </view>
        <view
          class="data-info"
          @click="
            () => {
              isPricing = true;
            }
          "
        >
          <view class="data-info-view"
            ><text class="number" style="color: black"
              ><input
                type="number"
                v-model="summaryDatas.priceQuantity"
                @focus="focus"
                disabled
                class="input-box" /></text
          ></view>
          <view class="data-info-view"
            ><text class="label"
              >计价/{{ summaryDatas.priceUnitName }}</text
            ></view
          >
        </view>
        <view class="data-info">
          <view class="data-info-view"
            ><text class="number" style="color: red"
              ><input
                type="number"
                v-model="summaryDatas.totalPrice"
                @focus="focus"
                class="input-box" /></text
          ></view>
          <view class="data-info-view"><text class="label">总金额</text></view>
        </view>
      </view>
      <!-- 销售单==其他订单 -->
      <sales-order
        :likeList="likeList"
        @getListOptionsPageBySpuId="getListOptionsPageBySpuId"
        @salesOrderConfirm="salesOrderConfirm"
        :snVoList="summaryDatas.snVoList"
        @delCloth="delCloth"
        @confirm="confirm"
        :salesData="summaryDatas"
        @inputChange="inputChange"
        v-if="
          pageSource == 'dbd' ||
          pageSource == 'xsd' ||
          pageSource == 'cgd' ||
          pageSource == 'thjs' ||
          pageSource == 'cgdreturn'
        "
        ref="xsd"
      ></sales-order>
      <!-- 客户订单 -->
      <customer-orders
        :likeList="likeList"
        @getListOptionsPageBySpuId="getListOptionsPageBySpuId"
        @salesOrderConfirm="salesOrderConfirm"
        :snVoList="summaryDatas.snVoList"
        @delCloth="delCloth"
        @confirm="confirm"
        :salesData="summaryDatas"
        @inputChange="inputChange"
        v-if="pageSource == 'khdd'"
        ref="xsd"
      ></customer-orders>
    </view>

    <view class="fixed-btn flex">
      <!-- <view class="flex check-color m-r-20">
        <u-icon name="arrow-left-double" style="transform: rotate(90deg);"></u-icon>
        <text class="m-l-10">查看已添加的颜色</text>
      </view> -->
      <template>
        <u-button
          text="下个款"
          type="primary"
          class="card-btn"
          shape="circle"
          color="#ddf0ff"
          border="none"
          @click="toNext"
        ></u-button>
        <u-button
          text="下个色"
          type="primary"
          class="save-btn"
          shape="circle"
          color="linear-gradient(to right, rgb(64, 158, 255), rgb(64, 158, 255), rgb(96, 180, 246), rgb(96, 180, 246))"
          @click="toNextColor(2)"
        ></u-button>
      </template>
    </view>

    <u-datetime-picker
      :show="paymentDaysShow"
      v-model="model.paymentDays"
      @confirm="paymentDaysShow = false"
      @cancel="paymentDaysShow = false"
      @close="paymentDaysShow = false"
      @change="paymentDaysChange"
      mode="date"
    ></u-datetime-picker>

    <!-- 计价弹框 -->
    <pricing
      v-if="isPricing"
      @onPickerSave="onPickerSave"
      @onPickerCencal="onPickerCencal"
      :item="summaryDatas"
    >
    </pricing>
    <!--  已选颜色列表-->
    <u-popup :show="isShow">
      <view class="dl-view">
        <view class="dt-view">1#</view>
        <view class="dd-view flex">
          <view class="no-view grey">无缸号</view>
          <view class="r-view">
            <text class="grey m-r-20">已选</text>
            <text class="red m-r-10">1匹</text>
            <text class="red">1米</text>
          </view>
        </view>
      </view>
    </u-popup>
    <!-- 删除该颜色 -->
    <u-modal
      :show="isDelShow"
      confirmText="删除"
      :showCancelButton="true"
      confirmColor="#409EFF"
      @cancel="onDelCancel"
      @confirm="onDelConfirm"
    >
      <view class="msg">
        {{ delColorMsg }}
      </view>
    </u-modal>
    <!-- 偏好设置 -->
    <u-popup
      :show="isLikeShow"
      mode="center"
      :round="5"
      @close="onLikeClose"
      :closeOnClickOverlay="true"
    >
      <view class="pop-ul">
        <view
          class="pop-li"
          :class="{ active: item.check }"
          v-for="(item, index) in likeList"
          :key="index"
          @click="onCheck(item)"
        >
          <u-icon
            name="checkbox-mark"
            color="#fff"
            class="m-r-20"
            size="24"
            v-if="item.check"
          ></u-icon>
          {{ item.label }}
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
import { getlist } from "@/apis/bill/information/warehouse";
import clIcon from "@/components/cl-icon/cl-icon.vue";
import { getOneLineCanUseStockByStockUnique } from "@/apis/bill/saleReserve";
import salesOrder from "./components/salesOrder.vue";
import customerOrders from "./components/customer-orders.vue";
import cgd from "./components/cgd.vue";
import pricing from "./components/pricing.vue";
export default {
  name: "customer-product-billing",
  components: {
    salesOrder,
    cgd,
    pricing,
    customerOrders,
    clIcon,
  },
  data() {
    return {
      // 显示删除颜色模态框
      isDelShow: false,
      delColorMsg: "",
      // 显示偏好设置
      isLikeShow: false,
      likeList: [
        { label: "宽幅/克重", check: true },
        { label: "规格", check: true },
        { label: "缸号", check: true },
        { label: "批号", check: true },
        { label: "辅编号/名称", check: true },
      ],
      // 显示已选择色信息
      isShow: false,
      // 显示计价弹框
      isPricing: false,
      // 显示相同部分内容
      whiteList: ["return", "salesOrder"],
      config: {
        title: "开单内容",
        color: "#ffffff",
        //背景颜色;参数一：透明度（0-1）;参数二：背景颜色（array则为线性渐变，string为单色背景）
        backgroundColor: [1, ["#409EFF", "#409EFF", "#60b4f6", "#60b4f6"]],
        rightButton: [
          {
            key: "btn1",
            txt: "去结算",
            icon: "",
            // position: "left",
          },
          {
            key: "btn2",
            txt: "",
            icon: "&#xed34;",
            // position: "left",
          },
        ],
        backTabPage: "",
        backPage: "",
        navigateBack: null,
        // navigateBack: 2
        // backTabPage: '/pages/application/index'
      },
      warehouseName: "",
      model: {
        unitPrice: "",
        deliveryTime: "",
        paymentDays: Number(new Date()),
        urgency: "",
      },
      paymentDaysShow: false,
      // 汇总全部数据
      summaryDatas: {
        storeName: "", // 仓库name
        storeId: "", //仓库id
        // // 产品的都可以拿到 不用了
        // "code": "", // 产品编号
        name: "", //产品名称
        spuId: "", // 产品ID
        auxiliaryCode: "", // 辅助编号
        auxiliaryName: "", // 辅助名称

        // // 颜色除了id不对别的都有
        colorNumber: "", // 色号
        color: null, // 颜色
        colorId: "", // 颜色id 是id
        auxiliaryColorNumber: "", // 辅助色号
        auxiliaryColor: "", //辅助颜色

        widthValue: "", // 幅宽
        widthUnitName: "", // 幅宽单位
        widthUnitId: "", // 幅宽id

        gramWeightValue: "", // 克重
        gramWeightUnitName: "", // 克重单位
        gramWeightUnitId: "", // 克重id

        spec: "", //规格
        // "brandName": "", //品牌
        // "styleNo": "", //款号
        // "quarterName": "", // 季节
        vatNo: "", // 缸号
        // "volumeNo": "", // 卷号

        unitName: "" || "米", //单位
        unitId: "" || "1597506549310423041", //单位id

        piecesCount: 0, //匹数
        quantity: 0, //数量

        // "typeName": "", // 类型name
        // "typeId": "", // 类型id

        spaceDiffTypeName: "+", //模式 name
        spaceDiffType: 0, // 模式id

        spaceDiffValue: 0, // 空差

        priceUnitName: "" || "米", // 计价单位name
        priceUnitId: "" || "1597506549310423041", // 计价单位id

        priceQuantity: 0, // 计价数量
        price: "0", // 单价

        // "discount": 0, // 折扣率  单位%
        totalPrice: 0, // 总金额

        lineStoreCanUsePiecesCount: 0, // 当前仓可发匹数
        lineStoreCanUseQuantity: 0, // 当前仓可发数量
        allStoreCanUsePiecesCount: 0, //全仓可发匹数
        allStoreCanUseQuantity: 0, //全仓可发数量

        // "taxRate": 0, // 税率
        // "priceTax": 0, // 含税单价
        totalPriceTax: 0, // 含税金额
        // "taxAmount": 0, // 税额
        batchNumber: "", //批号
        positionId: "", //仓位 id
        positionName: "", //仓位 Name
        // urgentLevelId: '',//紧急程度ID
        // urgentLevelName: '',//紧急程度Name
        // deliveryDate: '',//货期 Date格式的
        // deliveryDays: "6", // 货期天数
        // deliveryDays: '',//货期/天
        remarks: "", //备注
        priceBfDiscount: "", //折扣之前的价格
        snVoList: [],
      },
      // 页面来源
      pageSource: "",
      product: {},
      productPage: '',
      productPageType:'',
      // 设置
      isSetShow: false,
    };
  },
  onLoad(info) {
    // this.initData()
    this.pageSource = info.source;
    this.productPage = info.page;
    this.productPageType = info.type || null;
    // 如果this.pageSource == 'cgd'  走采购单逻辑
    // 如果this.pageSource == 'xsd'  走销售单逻辑
    // 如果this.pageSource == 'xsd'  走退货结算逻辑
    if (this.pageSource == "cgd") {
      this.summaryDatas = Object.assign(
        this.summaryDatas,
        this.$getPageParams("djRowItem").list
      );
      if (!this.summaryDatas.spaceDiffValue) {
        this.summaryDatas.spaceDiffValue = 0;
      }
    }

    if (this.pageSource == "xsd") {
      this.summaryDatas = Object.assign(
        this.summaryDatas,
        this.$getPageParams("djRowItem").list
      );
      if (!this.summaryDatas.spaceDiffValue) {
        this.summaryDatas.spaceDiffValue = 0;
      }
    }
    if (this.pageSource == "thjs") {
      this.summaryDatas = Object.assign(
        this.summaryDatas,
        this.$getPageParams("djRowItem").list
      );
      if (!this.summaryDatas.spaceDiffValue) {
        this.summaryDatas.spaceDiffValue = 0;
      }
    }
    if (this.pageSource == "khdd") {
      this.summaryDatas = Object.assign(
        this.summaryDatas,
        this.$getPageParams("djRowItem").list
      );

      if (!this.summaryDatas.spaceDiffValue) {
        this.summaryDatas.spaceDiffValue = 0;
      }
      this.getOneLineCanUseStockByStockUniques();
      this.summaryDatas.totalPriceTax = this.summaryDatas.totalPrice + 0;
      this.summaryDatas.id = null;
    }
    if (this.pageSource == "cgdreturn") {
      this.summaryDatas = Object.assign(
        this.summaryDatas,
        this.$getPageParams("djRowItem").list
      );
      if (!this.summaryDatas.spaceDiffValue) {
        this.summaryDatas.spaceDiffValue = 0;
      }
    }
    if (this.pageSource == "dbd") {
      this.summaryDatas = Object.assign(
        this.summaryDatas,
        this.$getPageParams("djRowItem").list
      );
      if (!this.summaryDatas.spaceDiffValue) {
        this.summaryDatas.spaceDiffValue = 0;
      }
    }
  },
  beforeDestroy() {
    uni.$off("on-warehouse-data");
    uni.$off("on-emergency-degree");
    uni.$off("on-selected-goods-width-gram");
    uni.$off("on-pricing-unit");
    uni.$off("on-switch-pricing-unit");
    uni.$off("on-color-data");
  },
  onShow() {
    // 获取偏好设置
    this.getupdatelikeList(0)
    // 紧急程度
    uni.$on("on-color-data", (data) => {
      this.summaryDatas.colorNumber = data.colorNumber;
      this.summaryDatas.color = data.color;
      this.summaryDatas.colorId = data.id;
      this.summaryDatas.auxiliaryColorNumber = data.auxiliaryColorNumber;
      this.summaryDatas.auxiliaryColor = data.auxiliaryColor;
      uni.$off("on-color-data");
    });

    // 获取仓库的信息
    uni.$on("on-warehouse-data", (data) => {
      this.summaryDatas.storeName = data.name;
      this.summaryDatas.storeId = data.id;
      uni.$off("on-warehouse-data");
    });
    //获取单位信息
    uni.$on("on-pricing-unit", (data) => {
      this.summaryDatas.unitName = data.label;
      this.summaryDatas.unitId = data.value;
      this.summaryDatas.priceUnitName = data.label;
      this.summaryDatas.priceUnitId = data.value;
      uni.$off("on-pricing-unit");
    });
    // 获取计价单位name
    uni.$on("on-switch-pricing-unit", (data) => {
      this.summaryDatas.priceUnitName = data.label;
      this.summaryDatas.priceUnitId = data.value;
      uni.$off("on-switch-pricing-unit");
    });

    // 紧急程度
    uni.$on("on-emergency-degree", (data) => {
      // console.log("on-emergency-degree", data);
      uni.$off("on-emergency-degree");
    });
    // 手动选择获取幅宽克重
    uni.$on("on-selected-goods-width-gram", (data) => {
      this.summaryDatas.gramWeightUnitId = data.gramWeightUnitId;
      this.summaryDatas.gramWeightUnitName = data.gramWeightUnitName;
      this.summaryDatas.gramWeightValue = data.gramWeightValue;
      this.summaryDatas.widthUnitId = data.widthUnitId;
      this.summaryDatas.widthUnitName = data.widthUnitName;
      this.summaryDatas.widthValue = data.widthValue;
    });
    const djRowItem = this.$getPageParams("djRowItem");
    if (djRowItem.info.isEcho) {
      this.config.navigateBack = 1;
    }
  },
  methods: {
    // 修改 || 获取当前的偏好设置
    getupdatelikeList(type){
      if(type == 0){
        this.likeList = this.$getPageParams("djRowItem").likeList
      }else{
        let item = this.$getPageParams("djRowItem")
        item.likeList = this.likeList
        this.$setPageParams("djRowItem", item)
      }
      
    },
    // 获取可发匹数
    getOneLineCanUseStockByStockUniques() {
      let billId = {
        spuId: this.summaryDatas.spuId,
        colorId: this.summaryDatas.colorId,
        unitId: this.summaryDatas.unitId,
        storeId: this.summaryDatas.storeId,
        widthValue: this.summaryDatas.widthValue,
        gramWeightValue: this.summaryDatas.gramWeightValue,
        spec: this.summaryDatas.spec,
      };
      getOneLineCanUseStockByStockUnique(billId).then((res) => {
        if (!res.flag) return;
        const data = res.data || {};
        this.summaryDatas.lineStoreCanUsePiecesCount =
          data.lineStoreCanUsePiecesCount;
        this.summaryDatas.lineStoreCanUseQuantity =
          data.lineStoreCanUseQuantity;
        this.summaryDatas.allStoreCanUsePiecesCount =
          data.allStoreCanUsePiecesCount;
        this.summaryDatas.allStoreCanUseQuantity = data.allStoreCanUseQuantity;
      });
    },
    // 左上角返回按钮
    onBack() {
      const djRowItem = this.$getPageParams("djRowItem");
      let dataItem = {};
      if (!djRowItem?.info.isEcho) {
        switch (this.pageSource) {
          case "cgd":
            // 采购单逻辑
            dataItem = this.$ls.get("cgdInformation");
            if (this.summaryDatas.quantity > 0) {
              const cdgdjRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              if (cdgdjRowItem.info.isEcho) {
                cgddataItem.productInformation[cdgdjRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("cgdInformation", cgddataItem);
              } else {
                cgddataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("cgdInformation", cgddataItem);
              }
            }
            break;
          case "xsd":
            // 销售单逻辑
            dataItem = this.$ls.get("xsdInformation");
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("xsdInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("xsdInformation", dataItem);
              }
            }
            break;
          case "thjs":
            // 销售单逻辑
            dataItem = this.$ls.get("thjsInformation");
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("thjsInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("thjsInformation", dataItem);
              }
            }
            break;
          case "khdd":
            // 客户订单逻辑
            dataItem = this.$ls.get("khddInformation");
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("khddInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("khddInformation", dataItem);
              }
            }
            uni.redirectTo({
              // url: `/pages/application/pages/cloth/customer-product/index?source=${this.pageSource}&type=${this.pageSource}`,
            });
            break;
          case "cgdreturn":
            // 销售单逻辑
            dataItem = this.$ls.get("cgdreturnInformation");
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("cgdreturnInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("cgdreturnInformation", dataItem);
              }
            }
            break;
        }
      }
      uni.redirectTo({
        url: `/pages/application/pages/cloth/customer-product/index?source=${this.pageSource}&type=${this.pageSource}`,
      });
      // 返回到产品页面
      // uni.navigateBack(1)
    },
    getListOptionsPageBySpuId() {
      const djRowItem = this.$getPageParams("djRowItem");
      if (djRowItem) {
        this.$Router.push({
          path: "/pages/application/pages/cloth/customer-product-billing/selectWidthValueGramWeight",
          query: {
            spuId: djRowItem.list.id,
          },
        });
      } else {
        // console.error("缺少当前单位");
      }
    },
    // 路由跳转
    toRoute(item) {
      this.$Router.push({
        path: item,
      });
    },
    // 输入框确认按钮
    onPickerSave(item) {
      // console.log("item",item,this.summaryDatas.snVoList);
      this.isPricing = false;
      this.summaryDatas.priceQuantity = Number(item.priceQuantity);
      if (this.summaryDatas.snVoList.length == 1 && item.groupValue) {
        // this.summaryDatas.quantity = item.priceQuantity;
        this.summaryDatas.snVoList[0].quantity = item.priceQuantity;
      } else if (this.summaryDatas.snVoList.length == 0 && item.groupValue) {
        // this.summaryDatas.quantity = item.priceQuantity;
      }
      if (this.$refs.xsd.fromData.price) {
        this.summaryDatas.totalPrice =
          this.summaryDatas.priceQuantity * this.$refs.xsd.fromData.price;
      }
    },
    // 输入框取消按钮
    onPickerCencal() {
      this.isPricing = false;
    },
    //输入框聚焦时触发
    focus() {
      this.$refs.xsd.focus();
    },
    // 空差的确认按钮
    salesOrderConfirm() {
      const xsd = this.$refs.xsd.fromData;
      this.counPtpricin(xsd);
    },
    // 计算空差的
    counPtpricin(xsd) {
      if (!xsd.spaceDiffTypeName) {
        xsd.spaceDiffTypeName = "+";
      }
      if (!xsd.spaceDiffValue) {
        xsd.spaceDiffValue = 0;
      }
      switch (xsd.spaceDiffTypeName) {
        case "+":
          this.summaryDatas.priceQuantity =
            this.summaryDatas.quantity +
            this.summaryDatas.piecesCount * xsd.spaceDiffValue;
          break;
        case "-":
          this.summaryDatas.priceQuantity =
            this.summaryDatas.quantity +
            this.summaryDatas.piecesCount * xsd.spaceDiffValue;
          break;
        case "×":
          this.summaryDatas.priceQuantity =
            (this.summaryDatas.quantity + xsd.spaceDiffValue / 100) *
            this.summaryDatas.piecesCount;
          break;
        case "÷":
          this.summaryDatas.priceQuantity =
            (this.summaryDatas.quantity / (xsd.spaceDiffValue / 100)) *
            this.summaryDatas.piecesCount;
          break;
        default:
          break;
      }
      if (this.$refs.xsd.fromData.price) {
        this.summaryDatas.totalPrice =
          this.summaryDatas.priceQuantity * this.$refs.xsd.fromData.price;
      }else{
        this.summaryDatas.totalPrice = 0
      }
    },
    delCloth() {
      this.summaryDatas.snVoList = this.$refs.xsd.fromData.snVoList;
      this.summaryDatas.piecesCount = this.$refs.xsd.fromData.snVoList.length;
      this.summaryDatas.quantity = 0;
      // this.summaryDatas.priceQuantity = 0
      for (
        let index = 0;
        index < this.$refs.xsd.fromData.snVoList.length;
        index++
      ) {
        this.summaryDatas.quantity += Number(
          this.$refs.xsd.fromData.snVoList[index].quantity
        );
        // this.summaryDatas.priceQuantity += Number(this.$refs.xsd.fromData.snVoList[index].quantity)
      }
      this.summaryDatas.totalPrice =
        this.summaryDatas.priceQuantity * this.$refs.xsd.fromData.price;
      this.counPtpricin(this.summaryDatas);
    },
    // 组件返回的事件
    confirm() {
      this.summaryDatas.snVoList = this.$refs.xsd.fromData.snVoList;
      this.summaryDatas.piecesCount = this.$refs.xsd.fromData.snVoList.length;
      this.summaryDatas.quantity = 0;
      // this.summaryDatas.priceQuantity = 0
      for (
        let index = 0;
        index < this.$refs.xsd.fromData.snVoList.length;
        index++
      ) {
        this.summaryDatas.quantity += Number(
          this.$refs.xsd.fromData.snVoList[index].quantity
        );
        // this.summaryDatas.priceQuantity += Number(this.$refs.xsd.fromData.snVoList[index].quantity)
      }
      this.summaryDatas.totalPrice =
        this.summaryDatas.priceQuantity * this.$refs.xsd.fromData.price;
      this.counPtpricin(this.summaryDatas);
    },
    inputPiecesChange(item) {
      if (this.pageSource == "cgd") {
        if (this.$refs.xsd.fromData.price) {
          this.summaryDatas.totalPrice =
            this.summaryDatas.quantity * this.$refs.xsd.fromData.price;
        }
      } else if (this.pageSource == "xsd") {
        if (this.$refs.xsd.fromData.price) {
          this.summaryDatas.totalPrice =
            this.summaryDatas.quantity * this.$refs.xsd.fromData.price;
        }
      } else if (this.pageSource == "thjs") {
        if (this.$refs.xsd.fromData.price) {
          this.summaryDatas.totalPrice =
            this.summaryDatas.quantity * this.$refs.xsd.fromData.price;
        }
      } else if (this.pageSource == "khdd") {
        if (this.$refs.xsd.fromData.price) {
          this.summaryDatas.totalPrice =
            this.summaryDatas.quantity * this.$refs.xsd.fromData.price;
        }
      } else if (this.pageSource == "cgdreturn") {
        if (this.$refs.xsd.fromData.price) {
          this.summaryDatas.totalPrice =
            this.summaryDatas.quantity * this.$refs.xsd.fromData.price;
        }
      }
      this.summaryDatas.priceQuantity = this.summaryDatas.quantity;
    },
    inputChange(item) {
      this.summaryDatas.totalPrice = this.summaryDatas.priceQuantity * item;
    },
    showCon() {
      return this.whiteList.includes(this.pageSource);
    },
    clickBtn(item) {
      if (item.key === "btn1") {
        switch (this.pageSource) {
          case "cgd":
            // 采购单逻辑
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              let dataItem = this.$ls.get("cgdInformation");
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("cgdInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("cgdInformation", dataItem);
              }
            }
            uni.redirectTo({
              url: `/pages/application/pages/cloth/procure/settlement/index`,
            });
            break;
          case "xsd":
            // 销售单逻辑
            // 获取当前传递的参数
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              let dataItem = this.$ls.get("xsdInformation");
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("xsdInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("xsdInformation", dataItem);
              }
            }

            uni.redirectTo({
              url: `/pages/application/pages/cloth/procure/settlement/sales?type=`+ this.productPageType,
            });
            break;

          case "thjs":
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              let dataItem = this.$ls.get("thjsInformation");
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("thjsInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("thjsInformation", dataItem);
              }
            }
            uni.redirectTo({
              url: `/pages/application/pages/cloth/procure/settlement/return`,
            });
            break;
          case "khdd":
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              let dataItem = this.$ls.get("khddInformation");
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("khddInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("khddInformation", dataItem);
              }
            }
            uni.redirectTo({
              url: `/pages/application/pages/cloth/procure/settlement/customer-orders`,
            });
            break;
          case "cgdreturn":
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              let dataItem = this.$ls.get("cgdreturnInformation");
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("cgdreturnInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("cgdreturnInformation", dataItem);
              }
            }
            uni.redirectTo({
              url: `/pages/application/pages/cloth/procure/settlement/cgd-return`,
            });
            break;

          case "dbd":
            if (this.summaryDatas.quantity > 0) {
              const djRowItem = this.$getPageParams("djRowItem");
              //获取销售单总的数据
              let dataItem = this.$ls.get("dbdInformation");
              if (djRowItem.info.isEcho) {
                dataItem.productInformation[djRowItem.info.index] =
                  this.summaryDatas;
                this.$ls.set("dbdInformation", dataItem);
              } else {
                dataItem.productInformation.push(this.summaryDatas);
                this.$ls.set("dbdInformation", dataItem);
              }
            }
            uni.redirectTo({
              url: `/pages/application/pages/cloth/procure/settlement/transfer-order`,
            });
            break;
        }
      } else {
        this.isSetShow = true;
      }
    },
    goPageWarehouse() {
      uni.navigateTo({
        url: `/pages/application/pages/information/warehouse/warehouse?type=list`,
      });
    },
    initData() {
      // 如果有数据就不进行重新覆盖
      if (this.warehouseName) {
        return;
      }
      let billId = {
        data: {
          isEnable: true,
        },
        page: {
          current: 1,
          size: 1,
          sort: "",
          order: "desc",
          total: 0,
          orders: [
            {
              column: "create_time",
              asc: false,
            },
          ],
        },
      };
      getlist(billId).then((res) => {
        if (!res.flag) return;
        const data = res.data || {};
        this.warehouseName = data.records[0].name;
        this.summaryDatas.storeName = data.records[0].name;
        this.summaryDatas.storeId = data.records[0].id;
      });
    },
    paymentDaysChange(e) {
      this.model.paymentDaysShow = e.value;
    },
    urgencyPageCLick() {
      uni.navigateTo({
        url: "pages/application/pages/finance/emergency-degree/index",
      });
    },

    // 下一款
    toNext() {
      const djRowItem = this.$getPageParams("djRowItem");
      switch (this.pageSource) {
        case "cgd":
          // 采购单逻辑 只有当数量大于0并且 djRowItem.info.isEcho == false 的时候才进行push 代表的是不是修改
          if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
            const cdgdjRowItem = this.$getPageParams("djRowItem");
            //获取销售单总的数据
            let cgddataItem = this.$ls.get("cgdInformation");
            if (cdgdjRowItem.info.isEcho) {
              cgddataItem.productInformation[cdgdjRowItem.info.index] =
                this.summaryDatas;
              this.$ls.set("cgdInformation", cgddataItem);
            } else {
              cgddataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("cgdInformation", cgddataItem);
            }
          }
          break;
        case "xsd":
          // 销售单逻辑
          if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
            // const djRowItem = this.$getPageParams("djRowItem");
            //获取销售单总的数据
            let dataItem = this.$ls.get("xsdInformation");
            if (djRowItem.info.isEcho) {
              dataItem.productInformation[djRowItem.info.index] =
                this.summaryDatas;
              this.$ls.set("xsdInformation", dataItem);
            } else {
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("xsdInformation", dataItem);
            }
          }
          break;
        case "thjs":
          // 销售单逻辑
          if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
            // const djRowItem = this.$getPageParams("djRowItem");
            //获取销售单总的数据
            let dataItem = this.$ls.get("thjsInformation");
            if (djRowItem.info.isEcho) {
              dataItem.productInformation[djRowItem.info.index] =
                this.summaryDatas;
              this.$ls.set("thjsInformation", dataItem);
            } else {
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("thjsInformation", dataItem);
            }
          }
          break;
        case "khdd":
          // 销售单逻辑
          if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
            // const djRowItem = this.$getPageParams("djRowItem");
            //获取销售单总的数据
            let dataItem = this.$ls.get("khddInformation");
            if (djRowItem.info.isEcho) {
              dataItem.productInformation[djRowItem.info.index] =
                this.summaryDatas;
              this.$ls.set("khddInformation", dataItem);
            } else {
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("khddInformation", dataItem);
            }
          }
          break;
        case "cgdreturn":
          // 销售单逻辑
          if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
            // const djRowItem = this.$getPageParams("djRowItem");
            //获取销售单总的数据
            let dataItem = this.$ls.get("cgdreturnInformation");
            if (djRowItem.info.isEcho) {
              dataItem.productInformation[djRowItem.info.index] =
                this.summaryDatas;
              this.$ls.set("cgdreturnInformation", dataItem);
            } else {
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("cgdreturnInformation", dataItem);
            }
          }
          break;
        case "dbd":
          // 销售单逻辑
          if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
            // const djRowItem = this.$getPageParams("djRowItem");
            //获取销售单总的数据
            let dataItem = this.$ls.get("dbdInformation");
            if (djRowItem.info.isEcho) {
              dataItem.productInformation[djRowItem.info.index] =
                this.summaryDatas;
              this.$ls.set("dbdInformation", dataItem);
            } else {
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("dbdInformation", dataItem);
            }
          }
          break;
      }
      // console.log('[ this.summaryDatas ] >', this.summaryDatas)
      // return
      // return
      uni.reLaunch({
          url: `/pages/application/pages/cloth/customer-product/index?source=${this.pageSource}`,
        });
    },
    // 下个色 type == 1当前数据换颜色  type == 2 点击了下个色
    toNextColor(type) {
      let djRowItem = this.$getPageParams("djRowItem");
      // djRowItem.list = this.summaryDatas;
      if (type == 2) {
        switch (this.pageSource) {
          case "cgd":
            // 采购单逻辑 只有当数量大于0并且 djRowItem.info.isEcho == false 的时候才进行push 代表的是不是修改
            if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
              let cgdInformation = this.$ls.get("cgdInformation");
              cgdInformation.productInformation.push(this.summaryDatas);
              this.$ls.set("cgdInformation", cgdInformation);
            }
            break;
          case "xsd":
            // 销售单逻辑
            if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
              let dataItem = this.$ls.get("xsdInformation");
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("xsdInformation", dataItem);
            }
            break;

          case "thjs":
            // 销售单逻辑
            if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
              let dataItem = this.$ls.get("thjsInformation");
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("thjsInformation", dataItem);
            }
            break;
          case "khdd":
            // 销售单逻辑
            if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
              let dataItem = this.$ls.get("khddInformation");
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("khddInformation", dataItem);
            } else {
            }
            break;
          case "khdd":
            // 客户订单逻辑
            if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
              let dataItem = this.$ls.get("cgdreturnInformation");
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("cgdreturnInformation", dataItem);
            }
            break;
          case "dbd":
            // 调拨单逻辑
            if (this.summaryDatas.quantity > 0 && !djRowItem.info.isEcho) {
              let dataItem = this.$ls.get("dbdInformation");
              dataItem.productInformation.push(this.summaryDatas);
              this.$ls.set("dbdInformation", dataItem);
            }
            break;
        }
        // this.$setPageParams("djRowItem", djRowItem);
        uni.navigateTo({
          url: `/pages/application/pages/cloth/color/index?socure=${this.pageSource}&page=${this.pageSource}`,
        });
      } else {
        uni.navigateTo({
          url: `/pages/application/pages/cloth/color/index?type=list&socure=${this.pageSource}&page=${this.pageSource}`,
        });
      }
    },
    // 显示删除该模态框
    onDelColor() {
      this.isDelShow = true;
      this.delColorMsg = `你确定要删除${this.summaryDatas.colorNumber}吗？`;
    },
    // 取消删除
    onDelCancel() {
      this.isDelShow = false;
      this.isSetShow = false;
    },
    // 确定删除
    onDelConfirm() {
      this.summaryDatas.colorNumber = "";
      this.summaryDatas.color = "";
      this.summaryDatas.colorId = "";
      this.summaryDatas.auxiliaryColorNumber = "";
      this.summaryDatas.colorNuauxiliaryColormber = "";
      this.onDelCancel();
    },
    // 显示偏好设置
    onLikeSet() {
      this.isLikeShow = true;
      this.isSetShow = false;
    },
    // 设置偏好设置
    onCheck(val) {
      val.check = !val.check;
      this.getupdatelikeList(1)
    },
    onLikeClose() {
      this.isLikeShow = false;
    },
  },
};
</script>

<style scoped lang="scss">
.top-box {
  background: linear-gradient(
    to right,
    rgb(64, 158, 255),
    rgb(64, 158, 255),
    rgb(96, 180, 246),
    rgb(96, 180, 246)
  );
  height: 80rpx;
}

.billing {
  padding-bottom: 140rpx;
}

.info-card {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin: 0 40rpx 40rpx;
  margin-top: 30rpx;
  margin-bottom: 0;
  background-color: #fff;
  padding: 20rpx;
  box-shadow: 2rpx 4rpx 14rpx #c7c7c7;
  align-items: center;

  .view {
    display: flex;
    flex-direction: row;
  }

  .info {
    margin-left: 20rpx;

    .title {
      font-size: 30rpx;
      color: #545454;
    }

    .colorNumber {
      color: #17c8ff;
      font-size: 28rpx;
    }

    .warehouse-view {
      display: flex;

      .warehouse {
        margin-right: 5rpx;
        color: #353535;
        font-size: 28rpx;
      }
    }
  }

  .change-color {
    color: #545454;
    font-size: 28rpx;
    text-align: right;
  }

  .data-info {
    flex: 1;

    .data-info-view {
      text-align: center;
    }

    .number {
      font-weight: 600;
      color: #17c8ff;
    }

    .label {
      margin-top: 5rpx;
      color: #888;
    }
  }
}

.form {
  margin: 0 40rpx 40rpx;
  margin-top: 30rpx;
  margin-bottom: 0;
  padding: 10rpx 30rpx;
  padding-bottom: 40rpx;
  background-color: #fff;

  .input-text {
    color: #b3b3b3;
  }
}

.urgency-text {
  color: #17c8ff;
  font-size: 15px;
  line-height: 17px;
  text-decoration: underline;
}

// .bottom-view {
//   position: fixed;
//   bottom: 0;
//   display: flex;
//   width: 100%;
//   padding: 30rpx;
//   margin: auto;
//   background-color: #FFFFFF;
// }
.form-view {
  background: #fff;

  .form-item {
    display: flex;
    align-items: center;
    padding: 20rpx 0;
    color: #7e7e7e;
    font-size: 30rpx;
    border-bottom: 1rpx solid #eee;

    .label {
      min-width: 120rpx;
      text-align: right;
      padding-left: 20rpx;
      color: #7e7e7e;
      font-size: 30rpx;
    }

    .value {
      flex: 1;

      .input-box {
        font-size: 30rpx;
      }

      .set {
        color: #409eff;
        text-decoration: underline;
      }
    }
  }
}

.check-color {
  // width: 900rpx;
  color: #999;
  display: flex;
  align-items: center;
}

// .fixed-btn {
//   position: fixed;
//   bottom: 0;
//   left: 0;
//   right: 0;
//   padding: 20rpx 30rpx 20rpx;
//   background: #fafafa;
.card-btn {
  flex: 1;
  color: #409eff !important;
  border-radius: 40rpx 0 0 40rpx;
}

.save-btn {
  flex: 1;
  border-radius: 0 40rpx 40rpx 0;
}

// }
.dl-view {
  padding: 20rpx 30rpx;

  .dt-view {
    margin-bottom: 20rpx;
  }

  .dd-view {
    display: flex;
    justify-content: space-between;

    .no-view {
      flex: 1;
    }

    .r-view {
      flex: 1;
    }
  }
}

.set-view {
  position: absolute;
  top: 100rpx;
  right: 10rpx;
  background: #fff;
  border-bottom: 1rpx solid #fff;
  z-index: 10;
  border: 1rpx solid #ddd;
  padding: 16rpx 20rpx;
  border-radius: 10rpx;

  .li-view {
    color: #333;
  }

  .up-icon {
    position: absolute;
    right: 16rpx;
    top: -36rpx;
  }
}

// .pop-ul {
//   width: 540rpx;
//   border-radius: 10rpx;
//   overflow: hidden;

//   .pop-li {
//     display: flex;
//     align-items: center;
//     justify-content: center;
//     font-size: 32rpx;
//     height: 90rpx;

//     &:nth-child(2n) {
//       background-color: #eee;
//     }
//   }

//   .active {
//     background-color: #27c8f8 !important;
//     color: #fff;
//   }
// }
</style>
